* Table 6 Baseline summary statistics and village-level balance : sample used to study household outcomes
* Last Updated, Niriksha Shetty 03/31/206

clear
clear mata
clear matrix
set maxvar 20000
set more off

pwd
cap cd c(`pwd')

estimates clear

use "../dta/reduced-form-master.dta", clear

*Using balanced panel
keep if ex_post_balp==1

*sum-stats
local vars "w_real_cons w_real_food_exp w_real_events_exp w_real_gifts_out w_real_nonfood_exp w_real_durables_exp w_real_income w_real_gifts_in w_real_sav w_real_lent w_real_borrow food_sufficiency_child fladder_std outlook_std control_std "
qui estpost summarize `vars' if mkt_year==2005
est sto A 
qui estpost summarize `vars' if originaltvillage==1 & mkt_year==2005 
est sto B 
qui estpost summarize `vars' if firstt_2007==1 & mkt_year==2005 
est sto C
qui estpost summarize `vars' if Tvillage==0 & mkt_year==2005 
est sto D
qui estpost summarize `vars' if firstt_2009==1 & mkt_year==2008 
est sto E
esttab A D B C E using "../output/sum-t6.csv", cells("mean(fmt(2))" replace sd(par fmt(2))) nolabel noabbrev title("Summary statistics") collabels("Mean") mtitle("Full" "Control" "T1" "T2" "T3" ) nonum replace 

* balance test
tempvar tmp
gen `tmp' = .
foreach var of local vars {
reg `var' originaltvillage firstt_2007 if mkt_year == 2005, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005
est sto A
esttab A using "../output/bal-t6.csv", cells("mean(fmt(2))") label noabbrev collabels("p-value") mtitle("") noobs nonum append
replace `tmp' = .
estimates clear
}
